import 'package:flutter/material.dart';

class DateTimeHandle{

  //将两个时间的差 换算成day minute second 等 例如 getData("2018-09-14 00:00:00","2018-09-14 11:33:22","day")
 static num getData(var startTime, var endTime,var diffType) {
    //将xxxx-xx-xx的时间格式 转为long
     num result;
    //将计算间隔类性字符转换为小写
   var  diff_type = diffType.toLowerCase();
       DateTime sTime = DateTime.parse(startTime.toString()); //开始时间
   DateTime eTime = DateTime.parse(endTime.toString()); //结束时间
    //作为除数的数字
    var timeType =1;
    switch (diff_type) {
      case"second":
        timeType =1000;
        break;
      case"minute":
        timeType =1000*60;
        break;
      case"hour":
        timeType =1000*3600;
        break;
      case"day":
        timeType =1000*3600*24;
        break;
      default:break;
    }
    result=(eTime.millisecondsSinceEpoch - sTime.millisecondsSinceEpoch) / double.parse(timeType.toString());
    return result ;
  }
//  alert(GetDate("2018-09-14 00:00:00","2018-09-14 11:33:22","day"));
}